package com.yc.favorite.servlet;

import com.yc.favorite.biz.UserBiz;
import com.yc.favorite.entity.User;
import com.yc.favorite.util.ServletUtils;
import com.yc.favorite.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login.s")
public class LoginServlet extends HttpServlet {

    UserBiz userBiz = new UserBiz();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletUtils.result("登录成功", resp,
                () -> {
                    User user = userBiz.login(req.getParameter("name"),
                            req.getParameter("pwd"));
                    req.getSession().setAttribute("myinfo", user);
                    return user;
                });
    }
}
